﻿using Blog.Model.Dto.Memento;
using Blog.Model.Dto.Tag;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Blog.Service
{
    public class TagService : ITagService
    {
        private ISqlSugarClient _db;
        public TagService(ISqlSugarClient db)
        {
            _db = db;
        }

        public ApiResult AddTag(TagAdd param)
        {
            var data = new Tag()
            {
                TagName = param.TagName,
                TagIntroduce = param.TagIntroduce,
                Colour = param.Colour,
            };
            int num = _db.Insertable(data).ExecuteCommand();
            return new ApiResult().OK();
        }

        public ApiResult DelTag(ListIds param)
        {
            throw new NotImplementedException();
        }

        public ApiResult TagList(ListParam param)
        {
            int page = param.PageIndex;
            int size = param.PageSize;
            int totalCount = 0;

            var data = _db.Queryable<Tag>().Where(m => !m.IsDelete)
                .OrderByDescending(m => m.CreateTime)
                .ToPageList(page, size, ref totalCount);

            return new ApiResult().OK(data, totalCount);
        }

        public ApiResult TagPrintenvList()
        {
            var data = _db.Queryable<Tag>().Where(m => !m.IsDelete).Select(m => new {m.Id,m.TagName}).ToList();
            return new ApiResult().OK(data);
        }

        public ApiResult UpTag(TagUp param)
        {
            throw new NotImplementedException();
        }
    }
}
